package com.ctjsoft.fileupload;

import com.ctjsoft.fileupload.entity.TMinioServer;
import com.ctjsoft.fileupload.mapper.TMinioServerMapper;
import com.ctjsoft.fileupload.utils.MinioClientUtils;
import io.minio.MinioClient;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SpringBootApplication
@EnableSwagger2
@MapperScan("com.ctjsoft.fileupload.mapper")
public class FileUploadApplication {

    @Autowired
    TMinioServerMapper tMinioServerMapper;

    public static void main(String[] args) {
        SpringApplication.run(FileUploadApplication.class, args);
    }

    /**
     * 初始化所有MinioClientUtil
     *
     * @return
     */
    @Bean("minioClientList")
    public Map initMinioClients() {
        HashMap<String, MinioClientUtils> minioClientMap = new HashMap<>();
        List<TMinioServer> minioServerList = tMinioServerMapper.getMinioServerList();
        minioServerList.stream().forEach((tMinioServer) -> {
            minioClientMap.put(tMinioServer.getServerName(), new MinioClientUtils(tMinioServer));
        });
        return minioClientMap;
    }
}
